package org.soarsky.wealthchengdu.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Gallery;

/**
 * 不带惯性的 Gallery ，一次只能滑动一张
 * @author liux
 *
 */
public class NoFilingGallery extends Gallery  {

	public static final long NO_DELAY = 0;
	
	public NoFilingGallery(Context context) {
		super(context);
	}

	public NoFilingGallery(Context context, AttributeSet attrs) {
		super(context, attrs);
	}

	public NoFilingGallery(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
	}
/*
	@Override
	public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
		return false;
	}*/
	
//	private boolean isEnable;
//	@Override
//	public boolean onTouchEvent(MotionEvent event) {
//		if (event.getAction() == MotionEvent.ACTION_DOWN) {
//			isEnable = mDelayTool.isMiliilsOver();
//		}
//		
//		isEnable = true;
//		if (isEnable) {
//			return super.onTouchEvent(event);
//		} else {
//			return true;
//		}
//	}
	@Override
	public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
		int kEvent;
		
		if (velocityX > 0) {
			// Check if scrolling left
			kEvent = KeyEvent.KEYCODE_DPAD_LEFT;
		} else {
			// Otherwise scrolling right
			kEvent = KeyEvent.KEYCODE_DPAD_RIGHT;
		}
		onKeyDown(kEvent, null);
		return true;
		
	}
	
	private OnDoubleClickListener mOnDoubleClickListener;
	
	public void setOnDoubleClickListener(OnDoubleClickListener listener) {
		mOnDoubleClickListener = listener;
	}
	
//	private DoubleClickTool mDoubleClickTool = new DoubleClickTool(PhotoBrowseConfig.DOUABLE_TAP);
//	
//	@Override
//	public boolean onSingleTapUp(MotionEvent e) {
//		if (mDoubleClickTool.isDoubleTap()) {
//			if (mOnDoubleClickListener != null) {
//				mOnDoubleClickListener.onDoubleClick(this);
//			}
//		}
//		return super.onSingleTapUp(e);
//	}
	
	public static interface OnDoubleClickListener{
		void onDoubleClick(View v);
	}
	
}
